<template>
  <div class="mydiscount-content">
    <div class="noimgbox" v-if="noimg == 1">
      <img src="@/assets/img/none.png" alt="">
    </div>
    <div class="discountlist" v-for="(item,index) in items" :key="index">
      <div class="disbox" @click="ding(item.dinid)">
        <div class="leftbox">
          <div class="money" v-if="item.name!=null">{{ item.name }}</div>
          <div class="money">{{ item.content }}</div>
          <div class="gray" style="text-decoration: line-through">原价：{{ item.sale }} 元</div>
          <div class="gray">现价：{{ item.zksale }}元！！</div>
        </div>
        <div class="rightbox" style="width: 250px;height: 250px">
          <img :src="item.img" >
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      noimg: 0,
      items: [],
      lists: []
    };
  },
  beforeCreate: function () {
    //创建前
  },
  created: function () {
    this.Suk_getlist();
    //创建后
  },
  beforeMount: function () {
    //挂载前
  },
  mounted: function () {
    //挂载后
  },
  beforeUpdate: function () {
    //更新前
  },
  update: function () {
    //更新后
  },
  methods: {
    tj(val) {
      var that = this;
      that.$toast.loading({
        message: "添加购物车..."
      });


      var Sukdata = {
        id: val
      };
      that.axios
        .post(that.baseUrl + "/taocan/taocanpList", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function (res) {
          if (res.request.status === 200) {
            if (res.data.meta.code == 200) {
              that.lists = res.data.data
              for (let i = 0; i < that.lists.length; i++) {
                var Sukdata = {
                  userId: localStorage.getItem("userid"),
                  dinId: val,
                  productId: that.lists[i].pid,
                  num: 1,
                  price: that.lists[i].price
                };
                // console.log(Sukdata);
                that.axios
                  .post(that.baseUrl + "/shopp/insertShopp", that.Qs.stringify(Sukdata), {
                    headers: {
                      "Content-Type": "application/x-www-form-urlencoded"
                    }
                  })
                  .then(function (res) {
                    if (res.request.status === 200) {
                      if (res.data.meta.code == 200) {
                        that.getlist(that.items[that.activeKey].classId);
                        that.$toast.clear();
                      } else if (res.data.meta.code == 501) {

                      }
                    }
                  });
              }

              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    },
    ding(xx) {
      localStorage.setItem("storeid", xx);
      this.tj(xx)
      this.$router.push({
        name: "storedetail"
      });
    },
    // 查询套餐
    Suk_getlist() {
      let that = this;
      that.$toast.loading({
        message: "加载中..."
      });
      let Sukdata = {
        userId: localStorage.getItem("userid"),
      };
      console.log(Sukdata);
      that.axios
        .post(that.baseUrl + "/taocan/taocanList", that.Qs.stringify(Sukdata), {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          }
        })
        .then(function (res) {
          if (res.request.status === 200) {
            console.log(res.data, 'red');
            if (res.data.meta.code == "501") {
              that.items = []
              that.$toast({
                message: '目前没有套餐'
              })
            }
            if (res.data.meta.code == 200) {
              that.items = res.data.data.list
              that.$toast.clear();
            } else if (res.data.meta.code == 501) {
            }
          }
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.discountlist {
  width: 90%;
  margin: 0 auto;
  background: #fff;
  border-radius: 0.2rem;
  margin-top: 0.3rem;

  .disbox {
    width: 90%;
    margin: 0 auto;
    padding: 0.3rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .leftbox {
      .money {
        color: #fe6c05;
        font-size: 0.45rem;
      }

      .gray {
        color: #cbcbcb;
        margin-top: 0.1rem;
        font-size: 0.3rem;
      }
    }

    .rightbox {
      display: flex;
      flex-direction: column;
      align-items: center;

      .distype {
        color: #fe6c05;
        font-size: 0.35rem;
      }

      .usebtn {
        color: #fe6c05;
        font-size: 0.35rem;
        border: 1px solid #de6c05;
        border-radius: 0.35rem;
        padding: 0.08rem 0.15rem;
        margin-top: 0.25rem;
      }
    }
  }
}

.noimgbox {
  width: 100%;

  img {
    width: 100%
  }
}
</style>
